package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.ParentRequestDTO;
import com.tianya.domain.entity.Parent;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.domain.vo.ParentVO;
import com.tianya.service.ParentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author TianYaGuoKe
 * @date 2025/5/26 23:57
 * @description ParentController
 */
@Api("家长管理")
@RestController
@RequestMapping("/parent")
public class ParentController {
    @Resource
    private ParentService parentService;

    @ApiOperation("创建家长")
    @PostMapping
    public Results createParent(@RequestBody ParentRequestDTO parentRequestDTO) {
        parentService.createParent(parentRequestDTO);
        return Results.success();
    }

    @ApiOperation("分页查询家长")
    @PostMapping("/page")
    public Results<PageResultVO<Parent>> pageList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                                  @RequestBody ParentRequestDTO parentRequestDTO) {
        return Results.success(parentService.pageList(pageNum, pageSize, parentRequestDTO));
    }

    @ApiOperation("根据id查询家长")
    @GetMapping("/{id}")
    public Results<ParentVO> getParentById(@PathVariable Long id) {
        return Results.success(parentService.getParentById(id));
    }

    @ApiOperation("根据id删除家长")
    @DeleteMapping("/{id}")
    public Results deleteParentById(@PathVariable Long id) {
        parentService.removeById(id);
        return Results.success();
    }

    @ApiOperation("更新家长信息")
    @PutMapping
    public Results updateParent(@RequestBody ParentRequestDTO parentRequestDTO) {
        //todo 待完善
        return Results.success();
    }
}
